-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Conversation
c5705c8
to
a0014ed
Compare
@mxnet-label-bot add [pr-work-in-progress] |
python/mxnet/ndarray/ndarray.py
Outdated
hdl = NDArrayHandle() | ||
check_call(_LIB.MXNDArrayCreateEx( | ||
c_array_buf(mx_uint, native_array('I', shape)), | ||
mx_uint(len(shape)), | ||
c_array_buf(mx_int64, native_array('q', shape)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to check python version if 'q' is supported
src/c_api/c_api.cc
Outdated
#if MXNET_USE_INT64_TENSOR_SIZE == 1 | ||
return MXNDArrayCreateExInt<int64_t>(shape, ndim, dev_type, dev_id, delay_alloc, dtype, out); | ||
#else | ||
return MXNDArrayCreateExInt<int32_t>(shape, ndim, dev_type, dev_id, delay_alloc, dtype, out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may not work. You can't just cast a mx_int64 pointer to int32_t pointer.
src/c_api/c_api.cc
Outdated
@@ -195,6 +196,20 @@ int MXNDArrayCreateEx(const mx_uint *shape, | |||
API_END(); | |||
} | |||
|
|||
int MXNDArrayCreateEx(const mx_int64 *shape, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also you are directly changing this C API which might break other language bindings that use this C API.
include/mxnet/c_api.h
Outdated
@@ -802,7 +807,8 @@ MXNET_DLL int MXNDArrayGetShape(NDArrayHandle handle, | |||
*/ | |||
MXNET_DLL int MXNDArrayGetShapeEx(NDArrayHandle handle, | |||
int *out_dim, | |||
const int **out_pdata); | |||
const int64_t **out_pdata); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are directly modifying C API which may break other language bindings. As we have agreed, it may be safer to create additional 64bit APIs instead.
include/mxnet/c_api.h
Outdated
@@ -55,7 +55,8 @@ extern "C" { | |||
#endif | |||
|
|||
/*! \brief manually define unsigned int */ | |||
typedef unsigned int mx_uint; | |||
typedef int64_t mx_int64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nit but,
As per the comment
/*! \brief manually define unsigned int */
Line
typedef int64_t mx_int64;
should be above it I guess, as it is not unsigned
.
include/mxnet/c_api.h
Outdated
@@ -548,15 +549,14 @@ MXNET_DLL int MXNDArrayCreate(const mx_uint *shape, | |||
* \param out the returning handle | |||
* \return 0 when success, -1 when failure happens | |||
*/ | |||
MXNET_DLL int MXNDArrayCreateEx(const mx_uint *shape, | |||
MXNET_DLL int MXNDArrayCreateEx(const mx_int64 *shape, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry if this is a stupid question, but why are we replacing mx_uint
(unsigned) with mx_int64
(signed)?
I would assume shape is always positive, shouldn't it be mx_uint64
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two reasons:
(1) According to Google C++ style guide: "Do not use an unsigned type merely to assert that a variable is non-negative." https://google.github.io/styleguide/cppguide.html#Integer_Types
(2) We intentionally changed to int because we may reserve the index -1 for supporting empty tensor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. Thank You for the explanation.
8fcde44
to
2d31323
Compare
src/c_api/c_api.cc
Outdated
@@ -513,6 +529,34 @@ int MXNDArrayGetShape(NDArrayHandle handle, | |||
API_END(); | |||
} | |||
|
|||
int MXNDArrayGetShapeExInt64(NDArrayHandle handle, | |||
int *out_dim, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent
9cebf08
to
fb9540e
Compare
include/mxnet/c_api.h
Outdated
|
||
MXNET_DLL int MXNDArrayGetShapeExInt64(NDArrayHandle handle, | ||
int *out_dim, | ||
const int64_t **out_pdata); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use mx_int64 to be consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@mxnet-label-bot add [pr-awaiting-review] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor changes!
Also, c_api_common.h and c_api_symbolic.cc still use int64_t
(simple find for int64_t
shows there are 22 places it's being used currently in the PR. Wanted clarity on what's the norm? When to use int64_t
and when to use mx_int64
? Is it even needed?)
@ChaiBapchya mx_uint is used for maintaining consistency with language bindings. For example python uses |
@mxnet-label-bot add[pr-awaiting-merge] |
python/mxnet/ndarray/ndarray.py
Outdated
@@ -105,6 +107,8 @@ | |||
_NDARRAY_BASIC_INDEXING = 0 | |||
_NDARRAY_ADVANCED_INDEXING = 1 | |||
|
|||
# Caching whether MXNet was built with INT64 support or not | |||
_INT64_TENSOR_SIZE_ENABLED = Features().is_enabled('INT64_TENSOR_SIZE') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still not efficient as Features() is still called everytime this variable is evaluated. There is no const variable in Python as in C++
e5e382a
to
458b1ae
Compare
7c9f02b
to
7ca3d32
Compare
7ca3d32
to
1d4f263
Compare
const mx_int64 **out_pdata) { | ||
MXAPIThreadLocalEntry<int64_t> *ret = MXAPIThreadLocalStore<int64_t>::Get(); | ||
API_BEGIN(); | ||
GetShape<mx_int64>(handle, out_pdata, out_dim, ret); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mx_int64 and int64_t are mixed here. Please consolidate them in your next PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Adding Large Index Support for slice operator * adding changes to fix py2 related error in CI/CD * fixing base.py * rearrange system call and slower Feature() call * refactoring c_api, c_symbolic_api, c_api_common * templatizing code * caching results of runtime features and minor refactoring * fixing local caching in ndarray shape
* Adding Large Index Support for slice operator * adding changes to fix py2 related error in CI/CD * fixing base.py * rearrange system call and slower Feature() call * refactoring c_api, c_symbolic_api, c_api_common * templatizing code * caching results of runtime features and minor refactoring * fixing local caching in ndarray shape
* Adding Large Index Support for slice operator * adding changes to fix py2 related error in CI/CD * fixing base.py * rearrange system call and slower Feature() call * refactoring c_api, c_symbolic_api, c_api_common * templatizing code * caching results of runtime features and minor refactoring * fixing local caching in ndarray shape
* Adding Large Index Support for slice operator * adding changes to fix py2 related error in CI/CD * fixing base.py * rearrange system call and slower Feature() call * refactoring c_api, c_symbolic_api, c_api_common * templatizing code * caching results of runtime features and minor refactoring * fixing local caching in ndarray shape
Description
Ops Supported: Slice
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.